package com.guet.ltomanagement.controller;


import com.guet.ltomanagement.common.entities.Constraint;
import com.guet.ltomanagement.common.entities.ResultBody;
import com.guet.ltomanagement.common.entities.SysUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author sjj
 * @since 2021-10-17
 */

@Api(tags = "系统用户接口")
@RestController
@RequestMapping("/sys/user")
public class SysUserController extends BaseController {
    @Autowired
    private BCryptPasswordEncoder passwordEncoder;


    /**
     * @Author sjj
     * @Description //TODO 注册用户的接口
     * @Date 2021/10/17 2021/10/17
     * @Param [sysUser]
     * @return com.sjj.taskmanagement.common.entities.ResultBody
     */
    @ApiOperation(value = "注册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sysUser", value = "用户类", required = true, dataType = "SysUser"),
    })
    @PostMapping("/register")
    public ResultBody register(@Validated @RequestBody SysUser sysUser)
    {
        return ResultBody.success(sysUserService.register(sysUser));
    }

    @ApiOperation(value = "删除用户")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Id", value = "用户Id", required = true, dataType = "Integer"),
    })
    @DeleteMapping("/delete")
    public ResultBody delete(@RequestParam Integer id)
    {
        return ResultBody.success(sysUserService.delete(id));
    }

    @ApiOperation(value = "获取用户列表")
    @GetMapping("/list")
    public ResultBody list()
    {
        return ResultBody.success(sysUserService.getUserList());
    }

    @ApiOperation(value = "根据id获取用户信息")
    @GetMapping("/info")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Id", value = "用户Id", required = true, dataType = "Integer"),
    })
    public ResultBody getUserInfoById(@RequestParam Integer id)
    {
        return ResultBody.success(sysUserService.getUserInfoById(id));
    }

    @ApiOperation(value = "获取当前用户信息")
    @GetMapping("/current")
    public ResultBody getCurrentUserInfo()
    {
        return ResultBody.success(sysUserService.getCurrentUserInfo());
    }

    @ApiOperation(value = "修改用户信息")
    @PostMapping("/update")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "sysUser", value = "用户类", required = true, dataType = "SysUser"),
    })
    public ResultBody update(@Validated @RequestBody SysUser sysUser)
    {
        return ResultBody.success(sysUserService.updateById(sysUser));
    }
}
